﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;

namespace HelperService
{
  public class HelperService : IHelperService
  {
    private string commandsTableName = "WP7CommandsTable";
    private string commandsTablePartitionKey = "Commands";
    private string devicesTableName = "WP7DeviceTable";
    private string devicesTablePartitionKey = "Devices";
    public string GetMyName(string name)
    {
      return "hello " + name + "to my service hosted in Azure";
    }

    public bool CreateQueue(string queueName)
    {
      return QueueHelper.Create(queueName);
    }

    public DataSet GetQueueList()
    {
      return QueueHelper.GetQueueList();
    }

    public bool SendMessage(string deviceID, string queueName, string message)
    {
      bool result = QueueHelper.Put(deviceID, queueName, message);
      return result;
    }

    public string GetMessage(string deviceID, string queueName, bool delete)
    {
      string result = QueueHelper.Get(deviceID, queueName, delete);
      return result;
    }

    public bool Delete(string queueName, string messageID, string receipt)
    {
      bool result = QueueHelper.Delete(queueName, messageID, receipt);
      return result;
    }

    public int GetQueueDepth(string queueName)
    {
      int result = QueueHelper.GetQueueDepth(queueName);
      return result;
    }

    public List<string> GetTablesList()
    {
      TableHelper tables = new TableHelper();
      return tables.ListTables();
    }

    public bool CreateTable(string tableName)
    {
      TableHelper tables = new TableHelper();
      return tables.CreateTable(tableName);
    }

    public bool DeleteTable(string tableName)
    {
      TableHelper tables = new TableHelper();
      return tables.DeleteTable(tableName);
    }

    public List<DeviceInfo> DisplayTable(string tableName)
    {
      TableHelper tables = new TableHelper();
      return tables.DisplayTable(tableName);
    }

    public List<CommTranslate> GetCommands()
    {
      TableHelper tables = new TableHelper();
      return tables.GetCommands();
    }

    public bool DeviceTable_InsertRow(string tableName, string partitionKey, string rowKey, DeviceInfo device)
    {
      TableHelper tables = new TableHelper();
      return tables.DeviceTable_InsertRow(tableName, partitionKey, rowKey, device);
    }

    public bool CommandsTable_InsertRow(string rowKey, CommTranslate command)
    {
      TableHelper tables = new TableHelper();
      return tables.CommandsTable_InsertRow(commandsTableName, commandsTablePartitionKey, rowKey, command);
    }

    public bool CommandsTable_DeleteRow(string rowKey)
    {
      TableHelper tables = new TableHelper();
      tables.DeleteRow(commandsTableName, commandsTablePartitionKey, rowKey);
      return true;
    }
  }
}